#!/bin/ksh


#=======================================================================
#
# ConfigureWebSMWebStartSSL - configure webstart client download files 
# to download SSL support.
#
# The wsm.jnlp file has a hardcoded reference to the wsmssl-ext.jnlp
# file, which in turn must be linked to a jnlp (wsmssl-us.jnlp,
# wsmssl-ex.jnlp or wsmssl-none.jnlp) that downloads the appropriate
# zip files for client security.
#
# If SSL support for strong encryption is installed (sslite-us.zip)
# then link to the jnlp that downloads sslite-us.zip.
#
# Else If SSL support for weak encryption is installed (sslite-ex.zip)
# then link to the jnlp that downloads sslite-ex.zip.
#
# If CA public key ring zip file (SMpubkr.zip) does not exist, create
# an empty one so there are not errors during download.  The user will
# replace it when he configures security.
#
# If no SSL support is installed, link to the jnlp that does not
# attempt to download. 
#
# Unlink before linking so that the mod time of the symbolic link is
# changed, otherwise webstart will not detect the change.
#
#=======================================================================


CODEBASE=/usr/websm/codebase

ConfigureWebSMWebStartSSL()
{

  pwd=${PWD}
  cd /usr/websm/html

  if [[ -r $CODEBASE/sslite-us.zip ]]; then
	unlink wsmssl-ext.jnlp >/dev/null 2>&1
	ln -sf wsmssl-us.jnlp wsmssl-ext.jnlp
	if [[ ! -a $CODEBASE/SMpubkr.zip ]]; then
		CreateEmptySMpubkrzip
	fi
  elif [[ -r $CODEBASE/sslite-ex.zip ]]; then
	unlink wsmssl-ext.jnlp >/dev/null 2>&1
	ln -sf wsmssl-ex.jnlp wsmssl-ext.jnlp
	if [[ ! -a $CODEBASE/SMpubkr.zip ]]; then
		CreateEmptySMpubkrzip
	fi
  else
	unlink wsmssl-ext.jnlp >/dev/null 2>&1
	ln -sf wsmssl-none.jnlp wsmssl-ext.jnlp
  fi

}


CreateEmptySMpubkrzip()
{
  export CLASSPATH=/usr/websm/codebase
  /usr/websm/bin/wjava com.ibm.websm.etc.MTzip $CODEBASE/SMpubkr.zip
}



#=========================================================================
#
#
#                     This is the MAIN of the script
#
#
#=========================================================================


ConfigureWebSMWebStartSSL

exit 0
